package com.zhwykj.greendao2020.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.zhwykj.greendao2020.bean.BookDao;
import com.zhwykj.greendao2020.bean.DaoMaster;

import org.greenrobot.greendao.database.Database;

/**
 * author gouplee
 * date 2020/3/14 11:43
 * remarks
 */

public class MyDaoHelper extends DaoMaster.OpenHelper {

    public MyDaoHelper(Context context, String name) {
        super(context, name);
    }

    public MyDaoHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        super.onUpgrade(db, oldVersion, newVersion);
        //升级数据库 这里重写的是类型SQLiteDatabase的升级方法
        //MigrationHelper是我们的工具类
        //PersonDao是数据库封装类
        //这种方法是保留原有的数据库封装类添加字段的方式
        MigrationHelper.migrate(db, BookDao.class);
    }
}
